home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Complementary Applications 2004 February / SGI IRIX 6.5 Complementary Applications 2004 February.iso / dist / cde.idb / usr / dt / share / examples / motif / dogs / Square.c.z / Square.c
Encoding:
C/C++ Source or Header  |  2003-11-18  |  9.4 KB  |  278 lines

  1. /*
  2.  * Square.c
  3.  *
  4.  * Copyright 2000, Silicon Graphics, Inc.
  5.  * ALL RIGHTS RESERVED
  6.  * 
  7.  * UNPUBLISHED -- Rights reserved under the copyright laws of the United
  8.  * States.   Use of a copyright notice is precautionary only and does not
  9.  * imply publication or disclosure.
  10.  *
  11.  * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
  12.  * Use, duplication or disclosure by the Government is subject to restrictions
  13.  * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
  14.  * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
  15.  * in similar or successor clauses in the FAR, or the DOD or NASA FAR
  16.  * Supplement.  Contractor/manufacturer is Silicon Graphics, Inc.,
  17.  * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
  18.  *
  19.  * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
  20.  * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
  21.  * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
  22.  * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
  23.  * GRAPHICS, INC.
  24.  */
  25. /* 
  26.  * (c) Copyright 1989, 1990, 1991, 1992 OPEN SOFTWARE FOUNDATION, INC. 
  27.  * ALL RIGHTS RESERVED 
  28. */ 
  29. /* 
  30.  * Motif Release 1.2
  31. */ 
  32. #ifdef REV_INFO
  33. #ifndef lint
  34. static char rcsid[] = "$XConsortium: Square.c /main/cde1_maint/1 1995/07/14 13:57:11 drk $"
  35. #endif
  36. #endif
  37.  
  38. /*****************************************************************************
  39. *
  40. *  Square.c - widget source file
  41. *
  42. ******************************************************************************/
  43.     
  44. #include <stdio.h>
  45. #include <Xm/Xm.h>
  46. #include <Mrm/MrmPublic.h>
  47. #include <Xm/BulletinBP.h>
  48. #include "SquareP.h"
  49.  
  50. #define Width(w) XmField((w),square_offsets,Core,width,Dimension)
  51. #define Height(w) XmField((w),square_offsets,Core,height,Dimension)
  52. #define BorderWidth(w) XmField((w),square_offsets,Core,border_width,Dimension)
  53. #define MajorDimension(w) XmField((w),square_offsets,Square,major_dimension,int)
  54.  
  55. #define MakeSquare(w) XmConstraintField((w),square_constraint_offsets, \
  56.             Square,make_square, Boolean)
  57.  
  58. static void ClassInitialize();
  59. static void Initialize();
  60. static Boolean SetValues();
  61. static void ConstraintInitialize();
  62. static Boolean ConstraintSetValues();
  63.  
  64. static XmPartResource resources[] = {
  65.     {
  66.     SquareNmajorDimension, SquareCMajorDimension, XmRInt, sizeof(int),
  67.     XmPartOffset(Square,major_dimension), XmRImmediate, (XtPointer)SquareWIDTH
  68.     }
  69. };
  70.  
  71. static XmPartResource constraints[] = {
  72.    {
  73.     SquareNmakeSquare, SquareCMakeSquare, XmRBoolean, sizeof(Boolean),
  74.     XmConstraintPartOffset(Square,make_square),
  75.     XmRImmediate, (XtPointer)False
  76.    }
  77. };
  78.  
  79.  
  80. externaldef(squareclassrec) SquareClassRec squareClassRec =
  81. {
  82.    {                    /* core_class fields    */
  83.       (WidgetClass) &xmBulletinBoardClassRec,   /* superclass   */
  84.       "Square",                 /* class_name           */
  85.       sizeof(SquarePart),       /* widget_size          */
  86.       ClassInitialize,          /* class_initialize     */
  87.       NULL,                     /* class init part proc */
  88.       False,                    /* class_inited         */
  89.       Initialize,               /* initialize           */
  90.       NULL,                     /* initialize_notify    */
  91.       XtInheritRealize,         /* realize              */
  92.       NULL,                     /* actions              */
  93.       0,                        /* num_actions          */
  94.       (XtResourceList)resources,/* resources            */
  95.       XtNumber(resources),      /* num_resources        */
  96.       NULLQUARK,                /* xrm_class            */
  97.       False,                    /* compress_motion      */
  98.       XtExposeCompressMaximal,  /* compress_exposure    */
  99.       False,                    /* compress_enterleave  */
  100.       False,                    /* visible_interest     */
  101.       NULL,                     /* destroy              */
  102.       XtInheritResize,          /* resize               */
  103.       XtInheritExpose,          /* expose               */
  104.       SetValues,                /* set_values           */
  105.       NULL,                     /* set_values_hook      */
  106.       XtInheritSetValuesAlmost, /* set_values_almost    */
  107.       NULL,                     /* get_values_hook      */
  108.       NULL,                     /* accept_focus         */
  109.       XtVersionDontCheck,       /* version              */
  110.       NULL,                     /* callback_private     */
  111.       XtInheritTranslations,    /* tm_table             */
  112.       XtInheritQueryGeometry,   /* Query Geometry proc  */
  113.       NULL,                     /* disp accelerator     */
  114.       NULL,                     /* extension            */    
  115.    },
  116.  
  117.    {                    /* composite_class fields */
  118.       XtInheritGeometryManager, /* geometry_manager       */
  119.       XtInheritChangeManaged,   /* change_managed         */
  120.       XtInheritInsertChild,     /* insert_child           */
  121.       XtInheritDeleteChild,     /* delete_child           */
  122.       NULL,                     /* extension              */
  123.    },
  124.  
  125.    {                    /* constraint_class fields */
  126.       (XtResourceList)constraints,  /* constraint resource     */
  127.       XtNumber(constraints),        /* number of constraints   */
  128.       sizeof(SquareConstraintPart), /* size of constraint      */
  129.       ConstraintInitialize,         /* initialization          */
  130.       NULL,                         /* destroy proc            */
  131.       ConstraintSetValues,          /* set_values proc         */
  132.       NULL,                         /* extension               */
  133.    },
  134.  
  135.    {                    /* manager_class fields   */
  136.       XtInheritTranslations,        /* translations           */
  137.       NULL,                         /* syn_resources          */
  138.       0,                            /* num_syn_resources      */
  139.       NULL,                         /* syn_cont_resources     */
  140.       0,                            /* num_syn_cont_resources */
  141.       XmInheritParentProcess,       /* parent_process         */
  142.       NULL,                         /* extension              */
  143.    },
  144.  
  145.    {                    /* bulletin_board_class fields */
  146.       FALSE,                        /* always_install_accelerators */
  147.       NULL,                         /* geo_matrix_create  */
  148.       XtInheritFocusMovedProc,      /* focus_moved_proc   */
  149.       NULL,                         /* extension          */
  150.    },
  151.  
  152.    {                    /* square_class fields  */
  153.       NULL,                         /* extension          */
  154.    }
  155. };
  156.  
  157. externaldef(squarewidgetclass) WidgetClass 
  158.     squareWidgetClass = (WidgetClass) &squareClassRec;
  159.  
  160. static XmOffsetPtr square_offsets;        /* Part offsets table */
  161. static XmOffsetPtr square_constraint_offsets;    /* Constraint offsets table */
  162.  
  163. /**********************************************************************
  164.  *
  165.  * SquareCreate - Convenience routine, used by Uil/Mrm.
  166.  *
  167.  *********************************************************************/
  168.  
  169. Widget SquareCreate(parent, name, arglist, nargs)
  170.     Widget parent;
  171.     char *name;
  172.     Arg *arglist;
  173.     int nargs;
  174. {
  175.     return(XtCreateWidget (name, squareWidgetClass, parent, arglist, nargs));
  176. }
  177.  
  178. /**********************************************************************
  179.  *
  180.  * SquareMrmInitialize - register Square widget class with Mrm
  181.  *
  182.  *********************************************************************/
  183.  
  184. int SquareMrmInitialize()
  185. {
  186.     return(MrmRegisterClass (MrmwcUnknown, "Square", "SquareCreate",
  187.                  SquareCreate, (WidgetClass)&squareClassRec));
  188. }
  189.  
  190. /**********************************************************************
  191.  *
  192.  * Class methods
  193.  *
  194.  *********************************************************************/
  195.  
  196. static void ClassInitialize()
  197. {
  198.     XmResolveAllPartOffsets(squareWidgetClass, &square_offsets,
  199.                 &square_constraint_offsets);
  200. }
  201.  
  202. static void Initialize(req, new)
  203.     SquareWidget req;
  204.     SquareWidget new;
  205. {
  206.     if (MajorDimension(new) != SquareWIDTH &&
  207.     MajorDimension(new) != SquareHEIGHT) {
  208.     XtWarning("Square: invalid majorDimension");
  209.     MajorDimension(new) = SquareWIDTH;
  210.     }
  211. }
  212.  
  213. static Boolean SetValues(curr, req, new)
  214.     SquareWidget curr;
  215.     SquareWidget req;
  216.     SquareWidget new;
  217. {
  218.     if (MajorDimension(new) != SquareWIDTH &&
  219.     MajorDimension(new) != SquareHEIGHT) {
  220.     XtWarning("Square: invalid majorDimension");
  221.     MajorDimension(new) = MajorDimension(curr);
  222.     }
  223.     return (False);
  224. }
  225.  
  226. static void ConstraintInitialize (req, new)
  227.     Widget req;
  228.     Widget new;
  229. {
  230.     Dimension m;
  231.  
  232.     if(MakeSquare(new) == True) {
  233.         if (MajorDimension(XtParent(new))==SquareWIDTH)
  234.             m = Width(new);
  235.         else
  236.             m = Height(new);
  237.  
  238.     XtResizeWidget(new, m, m, BorderWidth(new));
  239.     }
  240. }
  241.  
  242. static Boolean ConstraintSetValues (old, ref, new)
  243.     Widget old;
  244.     Widget ref;
  245.     Widget new;
  246. {
  247.     Boolean redraw = False;
  248.  
  249.     if (MakeSquare(new) != MakeSquare(old)) {
  250.     if(MakeSquare(new)==True) {
  251.             if (MajorDimension(XtParent(new))==SquareWIDTH)
  252.             Height(new) = Width(new);
  253.             else
  254.             Width(new) = Height(new);
  255.     }
  256.     else {
  257.         XtWidgetGeometry gi;
  258.         XtWidgetGeometry gp;
  259.  
  260.             if (MajorDimension(XtParent(new))==SquareWIDTH)
  261.             Height(new) = Height(new)/2;
  262.             else
  263.             Width(new) = Width(new)/2;
  264.  
  265.         gi.request_mode = CWWidth | CWHeight;
  266.         gi.width = Width(new);
  267.         gi.height = Height(new);
  268.         if (XtQueryGeometry(new, &gi, &gp) == XtGeometryAlmost) {
  269.         if (gp.request_mode && CWWidth != 0) Width(new) = gp.width;
  270.         if (gp.request_mode && CWHeight != 0) Height(new) = gp.height;
  271.         }
  272.     }
  273.     redraw = True;
  274.     }
  275.     return (redraw);
  276. }
  277.  
  278.